package com.avicit.zipkinkafkaesserver.factory;


import com.avicit.zipkinkafkaesserver.commands.DataListCommand;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class DataListCommandFactory implements Factory<DataListCommand>{
    private Map<Class<? extends DataListCommand>,DataListCommand> map = new ConcurrentHashMap<>();
    private  Class<? extends DataListCommand> dataListCommandClass;
    private static volatile DataListCommandFactory dataListCommandFactory;
    private DataListCommandFactory () {}

    public static DataListCommandFactory getInstance(){
        if (dataListCommandFactory == null) {
            synchronized (DataListCommandFactory.class) {
                if (dataListCommandFactory == null) {
                    dataListCommandFactory = new DataListCommandFactory();
                }
            }
        }
        return dataListCommandFactory;
    }

    @Override
    public DataListCommand create(Class<? extends DataListCommand> clazz) {
        DataListCommand dataListCommand = null;
        try {
            dataListCommand = clazz.newInstance();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        map.put(clazz,dataListCommand);
        dataListCommandClass = clazz;
        return dataListCommand;
    }


}
